package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.MyCollection;
import cn.wolfcode.trip.base.mapper.MyCollectionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMyCollectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyCollectionServiceImpl implements IMyCollectionService {

    @Autowired
    private MyCollectionMapper myCollectionMapper;

    /**
     * 我的收藏分页查询
     * @param qo
     * @return
     */
    @Override
    public PageInfo<?> queryForList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<MyCollection> list = myCollectionMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    /**
     * 收藏游记
     * @param entity
     */
    @Override
    public void collectTravel(MyCollection entity) {
        myCollectionMapper.insert(entity);
    }

    /**
     * 查询游记是否收藏
     * @param travelId
     * @param userId
     * @return
     */
    @Override
    public MyCollection queryCollection(Long travelId, Long userId) {
        MyCollection myCollection = myCollectionMapper.selectCollection(travelId, userId);
        return myCollection;
    }

    /**
     * 删除当前游记收藏
     * @param travelId
     */
    @Override
    public void deleteTravel(Long travelId, Long userId) {
        myCollectionMapper.deleteTravel(travelId, userId);
    }

    /**
     * 保存大攻略收藏
     * @param entity
     */
    @Override
    public void collectStrategy(MyCollection entity) {
        myCollectionMapper.insert(entity);
    }

    /**
     * 查询大攻略收藏
     * @param strategyId
     * @param userId
     * @return
     */
    @Override
    public MyCollection queryStrategyCollection(Long strategyId, Long userId) {
        MyCollection myCollection = myCollectionMapper.selectStrategyCollection(strategyId, userId);
        return myCollection;
    }

    /**
     * 删除大攻略收藏
     * @param strategyId
     * @param userId
     */
    @Override
    public void deleteStrategy(Long strategyId, Long userId) {
        myCollectionMapper.deleteStrategy(strategyId,userId);
    }

    /**
     * 保存日报收藏
     * @param myCollection1
     */
    public void collectNews(MyCollection myCollection1) {
        myCollectionMapper.insert(myCollection1);
    }

    /**
     * 查询日报收藏
     * @param newsId
     * @param userId
     * @return
     */
    public MyCollection queryNewsCollection(Long newsId, Long userId) {
        MyCollection myCollection = myCollectionMapper.selectNewsCollection(newsId, userId);
        return myCollection;
    }

    /**
     * 删除日报收藏
     * @param newsId
     * @param userId
     */
    public void deleteNews(Long newsId, Long userId) {
        myCollectionMapper.deleteNews(newsId,userId);

    }
}
